{extend name='layout/default'/}
{block name='main'}
<div id="control">
    {include file='admin/menu' /}
    <div class="rightControl">
        <form class="layui-form layui-form-pane" lay-filter="setting" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">站点名称</label>
                <div class="layui-input-block">
                    <input type="text" name="app_name" placeholder="请输入站点名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">首页标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" placeholder="请输入首页标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">站点logo</label>
                <div class="layui-input-block">
                    <input type="text" name="logo" placeholder="请输入网络地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">站点关键字</label>
                <div class="layui-input-block">
                    <input type="text" name="keywords" placeholder="请输入站点关键字，用,隔开" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">站点简介</label>
                <div class="layui-input-block">
                    <textarea name="description" placeholder="请输入站点简介" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">站点备案号</label>
                <div class="layui-input-block">
                    <input type="text" name="bah" placeholder="请输入站点备案号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新注册空间</label>
                <div class="layui-input-block" style="display: flex;align-items: center;gap: 10px">
                    <input type="number" name="default_storage_size" placeholder="请输入新用户注册初始空间 单位：KB"
                           class="layui-input" min="0" step="1000" lay-affix="number">
                    <div style="width: 80px" id="format">0KB</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上传限制</label>
                <div class="layui-input-block" style="display: flex;align-items: center;gap: 10px">
                    <input type="number" name="max_upload" placeholder="请输入图片上传大小限制 单位：KB"
                           class="layui-input" min="0" step="1000" lay-affix="number">
                    <div style="width: 80px" id="formatUpload">0KB</div>
                </div>
            </div>
            <div class="layui-form-item" style="display: flex">
                <label class="layui-form-label">注册功能</label>
                <div class="layui-input-inline" style="flex: 1;margin-right: 0;">
                    <select name="register">
                        <option value="0">关闭</option>
                        <option value="1" selected>开启</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" style="display: flex">
                <label class="layui-form-label">上传功能</label>
                <div class="layui-input-inline" style="flex: 1;margin-right: 0;">
                    <select name="uploads" lay-filter="aihao">
                        <option value="0">关闭</option>
                        <option value="1" selected>开启</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-normal" style="width: 100%;" lay-submit lay-filter="demo2">确认
                </button>
            </div>
        </form>
        <script>
            layui.use(function () {
                const form = layui.form;
                // 提交事件
                form.on('submit(demo2)', function (data) {
                    const field = data.field; // 获取表单字段值
                    $.ajax({
                        url: '/index/admin/setting',
                        type: 'post',
                        data: field,
                        success: res => {
                            if (res.code === 1) {
                                form.val('setting', res.data)
                                renderFormat()
                                layer.msg("保存成功")
                            }
                        }
                    })
                    return false; // 阻止默认 form 跳转
                });
                $.ajax({
                    url: '/index/admin/setting',
                    type: 'put',
                    success: res => {
                        form.val('setting', res.data)
                        renderFormat()
                    }
                })
            });
            $('[name="default_storage_size"]').on("input", function (e) {
                renderFormat()
            })
            $('[name="max_upload"]').on("input", function (e) {
                renderFormat()
            })
            function renderFormat(){
                $("#format").html(formatBytes($('[name="default_storage_size"]').val()))
                $("#formatUpload").html(formatBytes($('[name="max_upload"]').val()))
            }
        </script>
    </div>

</div>
{/block}